package com.itheima.aop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
@Component
@Aspect
public class RunTimeMonitorAdvice {
    //切入点,监控查询功能
    @Pointcut("execution(* com.itheima.service.*Service.find*(..))")
    public void pt(){

    }
    @Around("pt()")
    public Object runtimeAround(ProceedingJoinPoint pjp) throws Throwable {
        Signature signature = pjp.getSignature();
        String className = signature.getDeclaringTypeName();
        //方法名
        String name = signature.getName();
        //监测方法运行前的毫秒值
        long before = System.currentTimeMillis();
        Object proceed = pjp.proceed(pjp.getArgs());
        //之后的毫秒值
        long after = System.currentTimeMillis();
        long now = after-before;
        System.out.println(className+"中的"+name+"执行了:"+now+"毫秒");
        return proceed;
    }

    

}
